/*
    <one line to give the program's name and a brief idea of what it does.>
    Copyright (C) <year>  <name of author>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/


#include "archivetreeview.h"

ArchiveTreeView::ArchiveTreeView ()
{
	this->setAcceptDrops (true);
}

ArchiveTreeView::~ArchiveTreeView ()
{

}


bool ArchiveTreeView::dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action)
{
    QList<QUrl> urlList;
    QTreeWidgetItem *item;
    
    urlList = data->urls(); // retrieve list of urls
 
    foreach(QUrl url, urlList) // iterate over list
    {
        // make new QTreeWidgetItem and set its text
        // if parent is null - add top level item (this parent)
        if (parent == NULL) item = new QTreeWidgetItem(this); 
        else 
        // else add QTreeWidgetItem with parent and expand parent
        {    
            item = new QTreeWidgetItem(parent);
            parent->setExpanded( true );
        }
 
        // set item text
        item->setText( 0, url.toLocalFile() );
    }
 
    return true;    
}
 
 
QStringList ArchiveTreeView::mimeTypes () const
{
    QStringList qstrList;
    // list of accepted mime types for drop
    qstrList.append("text/uri-list");
    return qstrList;
}
 
 
Qt::DropActions ArchiveTreeView::supportedDropActions () const
{
    // returns what actions are supported when dropping
    return Qt::CopyAction | Qt::MoveAction;
}